package com.jiot.plugin.influx;

import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory;

import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.IPlugin;

public class InFluxDbPlugin implements IPlugin {
	
	public static InfluxDB influxDB;
	private String influxDbHost;
	private String influxDbUsername;
	private String influxDbPassword;
	
	
	public InFluxDbPlugin(String configFile) {
		Prop prop = PropKit.use(configFile);
		this.influxDbHost = prop.get("influxDb.host");
		this.influxDbUsername = prop.get("influxDb.username");
		this.influxDbPassword = prop.get("influxDb.password");
	}

	@Override
	public boolean start() {
		if(influxDB == null){}
			influxDB = InfluxDBFactory.connect(this.influxDbHost, this.influxDbUsername, this.influxDbPassword);
		
		return true;
	}

	@Override
	public boolean stop() {
		if(influxDB != null){
			influxDB.close();
		}
		return false;
	}

	
	
	public static InfluxDB getInfluxDB() {
		return influxDB;
	}

	public static void setInfluxDB(InfluxDB influxDB) {
		InFluxDbPlugin.influxDB = influxDB;
	}

	public String getInfluxDbHost() {
		return influxDbHost;
	}

	public void setInfluxDbHost(String influxDbHost) {
		this.influxDbHost = influxDbHost;
	}

	public String getInfluxDbUsername() {
		return influxDbUsername;
	}

	public void setInfluxDbUsername(String influxDbUsername) {
		this.influxDbUsername = influxDbUsername;
	}

	public String getInfluxDbPassword() {
		return influxDbPassword;
	}

	public void setInfluxDbPassword(String influxDbPassword) {
		this.influxDbPassword = influxDbPassword;
	}
	
	

}
